
class UserNameException extends Exception{
    public UserNameException(String message){
        super(message);
    }
}
class PasswordException extends Exception{
    public PasswordException(String message) {
        super(message);
    }
}

public class Login {
    String username = "admin";
    String password = "12345678";

    public void login(String username, String password) throws UserNameException,PasswordException{
        if (!username.equals(this.username)){
            throw new UserNameException("用户名错误");
        }
        if (!password.equals(this.password)){
            throw new PasswordException("密码错误");
        }
        System.out.println("登录成功");
    }

    public static void main(String[] args) {
        Login login = new Login();
        try {
            login.login("张三","12345678");
        }catch (UserNameException e){
            e.printStackTrace();
        } catch (PasswordException e) {
            e.printStackTrace();
        }
        try {
            login.login("admin","23456789");
        }catch (UserNameException e){
            e.printStackTrace();
        } catch (PasswordException e) {
            e.printStackTrace();
        }
        try {
            login.login("admin","12345678");
        }catch (UserNameException e){
            e.printStackTrace();
        } catch (PasswordException e) {
            e.printStackTrace();
        }
    }
}
